package com.zjq.cloud.user.controller;

import com.zjq.cloud.user.entity.User;
import com.zjq.cloud.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController // @ResponseBody+@Controller
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    // 用于将 URL 路径中的变量值绑定到方法参数上
    @GetMapping("/findUserById/{userId}")
    public User findUserById(@PathVariable("userId") Long userId) {
        return userService.findUserById(userId);
    }

    @GetMapping("/testToken/{userId}")
    public User findUser(@PathVariable("userId") Long userId,
                         @RequestHeader("token") String token) {
        log.info("用户微服务的findUser方法执行了，获取请求头参数:{}", token);
        return userService.findUserById(userId);
    }
}